import java.util.Scanner;
//Sets the class to enable you to use the buffer reader
class Loan_Payment_Calculator {
	public static void main(String args[]) {
		Scanner m_user_input = new Scanner(System.in);
		//Prints out the main menu
		System.out.println
		("This is a loan payment calculator.");
		System.out.println
		("Choose a task to perform:");
		System.out.println
		("--------------------------");
		System.out.println
		("1) Enter number 1 for a simple calculation.");
		System.out.println
		("2) Enter number 2 for more advanced calculation.");
		System.out.println
		("3) Enter anything else to exit the program.");
		//Converts operation string into integer 
		int v_operation = m_user_input.nextInt();
		//Checks if operation chosen is number 1
		if (v_operation==1){
			System.out.println
			("You have selected the first operation.");
			System.out.println
			("Enter interest rate of loan.");
			//Converts the rate given in integer to the proper form
			double v_rate = m_user_input.nextDouble()/1200;
			System.out.println
			("Enter loan expiration in years.");
			double v_years = m_user_input.nextDouble();
			System.out.println
			("Enter desired loan amount.");
			double v_amount = m_user_input.nextDouble();
			//Calculates monthly payment with the given values
			double v_monthly_payment = (v_rate+(v_rate/
					(Math.pow(1+v_rate, v_years*12)-1)))*v_amount;
			System.out.println
			//Prints the monthly payment
			("The monthly payment is "+v_monthly_payment);
			System.out.println
			("Bye bye!!!");
			//Forces exit of program
			System.exit(0);
		}
		//Checks if operation chosen is number 2
		if (v_operation==2){
			System.out.println
			("You have selected the second operation.");
			System.out.println
			("Enter loan expiration in years");
			int v_years2 = m_user_input.nextInt();
			System.out.println
			("Enter desired loan amount");
			double v_amount2 = m_user_input.nextDouble();
			//Checks if years given falls into 1st rate category of 7.25%
			if (v_years2<8){
				//Calculates monthly payment with the given values
				double v_monthly_payment2 = (0.0725 * v_amount2 / 12) /
						(1.0 - Math.pow(((0.0725 / 12) + 1.0), (-(v_years2*12))));
				//Calculates total payment with the given values
				double v_total_payment = v_monthly_payment2*v_years2;
				System.out.println
				//Prints monthly payment
				("The monthly payment is "+v_monthly_payment2);
				System.out.println
				//Prints total payment
				("The total payment is "+v_total_payment);
				System.out.println
				//Forces exit of program
				("Bye bye!!!");
				System.exit(0);
			}
			//Checks if years given falls into 2nd rate category of 8.5%
			if ((v_years2>7)&&(v_years2<16)){
				//Calculates monthly payment with the given values
				double v_monthly_payment2 = (0.085 * v_amount2 / 12) /
						(1.0 - Math.pow(((0.085 / 12) + 1.0), (-(v_years2*12))));
				//Calculates total payment with the given values
				double v_total_payment = v_monthly_payment2*v_years2;
				System.out.println
				//Prints monthly payment
				("The monthly payment is "+v_monthly_payment2);
				System.out.println
				//Prints total payment
				("The total payment is "+v_total_payment);
				System.out.println
				("Bye bye!!!");
				//Forces exit of program
				System.exit(0);
			}
			//Checks if years given falls into 3rd rate category of 9%
			if (v_years2>15){
				//Calculates monthly payment with the given values
				double v_monthly_payment2 = (0.09 * v_amount2 / 12) /
						(1.0 - Math.pow(((0.09 / 12) + 1.0), (-(v_years2*12))));
				//Calculates total payment with the given values
				double v_total_payment = v_monthly_payment2*v_years2;
				System.out.println
				//Prints monthly payment
				("The monthly payment is "+v_monthly_payment2);
				System.out.println
				//Prints total payment
				("The total payment is "+v_total_payment);
				System.out.println
				//Forces exit of program
				("Bye bye!!!");
				System.exit(0);
			}    
		}
		//Checks if operation given is anything else but number 1 and 2
		if ((v_operation!=1) && (v_operation!=2)){
			System.out.println
			("Bye bye!!!");
			//Forces exit of program
			System.exit(0);
		}
	}
}